package com.usm.Laborator1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class FourC {

    private static final Scanner scanner = new Scanner(System.in);
    private static final List<Integer> A = new ArrayList<>();
    private static final List<Integer> B = new ArrayList<>();
    private static final List<Integer> C = new ArrayList<>();

    public static void main(String[] args) {

        //Initializing A and B arrays
        System.out.println("Introduceti valorile pentru A: \n");
        insertValuesForArray(A);
        System.out.println("Introduceti valorile pentru B: \n");
        insertValuesForArray(B);

        //Calc C array
        calcC(A, B, C);
        //Show to user result
        System.out.println("A intersection B : ");
        printList(C);
    }

    public static void insertValuesForArray(List<Integer> array) {
        System.out.println("-f : pentru a finisa sirul ");
        boolean isTrue = true;
        while (isTrue) {
            String val = scanner.next();
            //check for finalize symbol
            if (val.equalsIgnoreCase("-f")) {
                isTrue = false;
            } else {
                array.add(Integer.valueOf(val));
            }
        }
    }

    public static void calcC(List<Integer> arrA, List<Integer> arrB, List<Integer> arrC) {
        for (Integer elementA : arrA) {
            for (Integer elementB : arrB) {
                if (elementA == elementB) {
                    arrC.add(elementA);
                }
            }
        }
    }

    public static void printList(List<Integer> array) {
        for (Integer element : array) {
            System.out.print("\t" + element);
        }
    }
}
